<template>
  <div v-if="visible" class="my-apps-detail-modal" @click.self="closeModal">
    <div class="my-apps-detail-content">
      <div class="my-apps-detail-header">
        <h3><i class="el-icon-menu"></i> 我的应用</h3>
        <el-button 
          icon="el-icon-close" 
          circle 
          size="small"
          class="header-close-btn"
          @click="closeModal"
        ></el-button>
      </div>
      <div class="my-apps-detail-body">
        <div class="app-grid">
          <div v-for="app in apps" :key="app.id" class="app-item" @click="openApp(app)">
            <div class="app-icon">{{ app.icon }}</div>
            <p class="app-name">{{ app.name }}</p>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'MyAppsDetail',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    apps: {
      type: Array,
      default: () => []
    }
  },
  methods: {
    closeModal() {
      this.$emit('close');
    },
    openApp(app) {
      if (app.route) {
        this.$router.push(app.route);
        this.closeModal();
      }
    }
  }
}
</script>

<style scoped>
.my-apps-detail-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

.my-apps-detail-content {
  background-color: #fff;
  border-radius: 4px;
  width: 80%;
  max-width: 700px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
}

.my-apps-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid #e6e6e6;
  background-color: #f8f8f8;
  border-radius: 4px 4px 0 0;
}

.my-apps-detail-header h3 {
  margin: 0;
  font-size: 16px;
  color: #333;
  display: flex;
  align-items: center;
  font-weight: normal;
}

.my-apps-detail-header h3 i {
  margin-right: 8px;
  color: #666;
}


.my-apps-detail-body {
  padding: 20px;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 20px;
}

.app-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s;
}

.app-item:hover {
  transform: translateY(-3px);
}

.app-icon {
  width: 40px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  font-size: 24px;
  margin-bottom: 8px;
  background-color: #f5f7fa;
  border-radius: 8px;
}

.app-name {
  font-size: 12px;
  color: #666;
  text-align: center;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}
</style>